/**
 * Copyright (c) Salomon Automation GmbH
 */
package ro.cuzma.larry.bookscollection.persistance.xml;

import ro.cuzma.larry.bookscollection.md.Author;
import ro.cuzma.larry.bookscollection.md.Book;
import ro.cuzma.larry.persistance.xml.XMLNodeList;
import ro.cuzma.larry.persistance.xml.XMLObject;
import ro.cuzma.larry.persistance.xml.XMLSimpleIdValue;
import ro.cuzma.larry.persistance.xml.XMLTagFactory;
import ro.cuzma.larry.persistance.xml.XMLTagValue;
import ro.cuzma.larry.persistance.xml.XMLTagValueList;
import ro.cuzma.larry.persistance.xml.exception.XMLException;

public class XMLFactoryLibrary implements XMLTagFactory {

    public XMLObject getHelper(String tagName) throws XMLException {
        if (tagName != null) {
            if (tagName.equals(XMLTags.LIBRARY)) {
                return new LibraryHelper();
            } else if (tagName.equals(XMLTags.BOOK)) {
                return new BookHelper();
            } else if (tagName.equals(XMLTags.AUTHOR)) {
                return new AuthorHelper();
            } else if (tagName.equals(XMLTags.LANGUAGEID) || tagName.equals(XMLTags.AUTHORID)
                    || tagName.equals(XMLTags.SERIES)) {
                return new XMLTagValue(tagName);
            } else if (tagName.equals(XMLTags.LIBRARY_AUTHORS)) {
                return new XMLNodeList<AuthorHelper, Author>(tagName, XMLTags.AUTHOR);
            } else if (tagName.equals(XMLTags.BOOK_AUTHORS)) {
                return new XMLTagValueList<Author>(tagName, XMLTags.AUTHORID);
            } else if (tagName.equals(XMLTags.LIBRARY_BOOKS)) {
                return new XMLNodeList<BookHelper, Book>(tagName, XMLTags.BOOK);
            } else if (tagName.equals(XMLTags.LANGUAGE) || tagName.equals(XMLTags.FORMAT)
                    || tagName.equals(XMLTags.TYPE)) {
                return new XMLSimpleIdValue(tagName);
            } else {
                throw new XMLException("No type defined for tag: <" + tagName + ">.");
            }
        } else {
            throw new XMLException("tagName must not be null");
        }
    }
}
